| Conditions | 1 |
| Paths | 1 |
| Total Lines | 86 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 7 | ||
| Bugs | 0 | Features | 2 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** |
||
| 17 | describe('Test database', function () { |
||
| 18 | before(function () { |
||
| 19 | db.add('subtitle', 'pob').store() |
||
| 20 | db.addEnv({'MOOV_SEARCH': 'dope'}) |
||
| 21 | }); |
||
| 22 | |||
| 23 | it ('expect to return an error if file is not a json', function () { |
||
| 24 | expect(() => { database.setFile('../db.txt') }).to.throw('The database file must be a json file') |
||
| 25 | }) |
||
| 26 | |||
| 27 | it ('expect database to be a string and equal parameter', function () { |
||
| 28 | expect(db.database) |
||
| 29 | .to.be.a('string') |
||
| 30 | .to.be.equal(file) |
||
| 31 | }) |
||
| 32 | |||
| 33 | it ('expect to be an object and contains subtitle property', function () { |
||
| 34 | expect(db.add('subtitle', 'pob').data) |
||
| 35 | .to.be.an('object') |
||
| 36 | .to.have.property('subtitle', 'pob') |
||
| 37 | }) |
||
| 38 | |||
| 39 | it ('expect file to exists and is a json', function () { |
||
| 40 | expect(file) |
||
| 41 | .to.be.a.file() |
||
| 42 | .with.json |
||
| 43 | }) |
||
| 44 | |||
| 45 | it ('expect an error if file can\'t be created', function () { |
||
| 46 | expect(database.setFile('/home/db.json').add('key', 'value').store()) |
||
| 47 | .to.be.an.error |
||
| 48 | }) |
||
| 49 | |||
| 50 | it ('expect to be an empty object', function () { |
||
| 51 | database.setFile('/home/db.json').data = {} |
||
| 52 | |||
| 53 | expect(database.setFile('/home/db.json').get()) |
||
| 54 | .to.be.an('object') |
||
| 55 | .to.be.empty |
||
| 56 | }) |
||
| 57 | |||
| 58 | it ('expect to be an not empty object', function () { |
||
| 59 | expect(database.setFile(file).get()) |
||
| 60 | .to.be.an('object') |
||
| 61 | .to.not.empty |
||
| 62 | }) |
||
| 63 | |||
| 64 | it ('expect to be an object and contains subtitle', function () { |
||
| 65 | expect(db.get()) |
||
| 66 | .to.be.an('object') |
||
| 67 | .to.have.property('subtitle', 'pob') |
||
| 68 | }) |
||
| 69 | |||
| 70 | it ('expect to be a string and is equal pob', function () { |
||
| 71 | expect(db.get('subtitle')) |
||
| 72 | .to.be.an('string') |
||
| 73 | .to.be.equal('pob') |
||
| 74 | }) |
||
| 75 | |||
| 76 | it ('expect an error if key don\'t exists in file', function () { |
||
| 77 | expect(() => { db.get('potatoes') }) |
||
| 78 | .to.throw('potatoes is undefined') |
||
| 79 | }) |
||
| 80 | |||
| 81 | it ('expect an error if typeof is not a object', function () { |
||
| 82 | expect(() => { db.massive('test') }) |
||
| 83 | .to.throw('data must be an object') |
||
| 84 | }) |
||
| 85 | |||
| 86 | it ('expect to be an object', function () { |
||
| 87 | expect(db.massive({'subtitle': 'pob', 'quality': '720p'}).data) |
||
| 88 | .to.be.an('object') |
||
| 89 | .to.have.property('subtitle') |
||
| 90 | }) |
||
| 91 | |||
| 92 | it ('expect an error if parameter is not a object', function () { |
||
| 93 | expect(() => { db.addEnv('test') }) |
||
| 94 | .to.throw('data must be an object') |
||
| 95 | }) |
||
| 96 | |||
| 97 | it ('expect to be an object and contains search', function () { |
||
| 98 | expect(process.env) |
||
| 99 | .to.be.an('object') |
||
| 100 | .to.have.property('MOOV_SEARCH') |
||
| 101 | }) |
||
| 102 | }) |
||
| 103 |